home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9305 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: problem with bc++ (2) answers please
  5. Date: 29 Feb 1996 22:10:56 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h589g$5hf@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.230
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. aragonne@mail.planete.net (ragonnet alain) writes:
  14. > /*********************************************************************
  15. > *  PROGAMME AVEC BC++ VERSION 4.52
  16. > *********************************************************************/
  17. > #include<stdio.h>
  18. > main( void)
  19. > {
  20. >     int tab[]= { 0, 1, 2}, *ptr= tab;
  21. >     printf("\n ref: %d , pointeur: %d\n", ptr, *ptr);
  22. > /*instruction qui ne fonctionne pas avec BC++ */ (this instrucion is not ok with BC++)
  23. >     printf("\n ref: %d", ptr);
  24. >     printf("\n pointeur: %d", *ptr);
  25. > /*Ces 2 instructions fonctionnent correctement */(this two instructions are ok )
  26. > }
  27. > /*
  28. >  ref: 3672 , pointeur: 0
  29. >  ref: 3672
  30. >  pointeur: 0
  31. >  Peut-on me dire d'ou vient le probleme.Ce programme fonctionne
  32. >  correctement avec QC 2.5 par exemple*/
  33. >  
  34. >  Can you tell me where is the problem please.This program is working well
  35. >  with QC 2.5 for exemple*/
  36. >  thank you for answers
  37.  
  38. I'm not sure what's the matter with my server; I think my response didn't
  39. make it, so once again...
  40.  
  41. Generally, you can't use "%d" to printf a pointer value. "%d" is used to
  42. print an integer and a pointer is not guaranteed to have the same size
  43. as the integer. On MSDOS machines the pointer size depends on the memory
  44. model. If using the SMALL model everything is fine since both integers and
  45. pointers are two bytes. In the large model, however, a pointer is four
  46. bytes. Thus, a call like printf( "%d %d", ptr, *ptr ) would first print
  47. the lower word of the pointer value and then the higher word. Just correct
  48. the first "%d" to "%p" or "%lp" and it will work.
  49.  
  50. Bye
  51.  
  52. Roman
  53.  
  54.